package cn.gov.anhai.controller;

import cn.gov.anhai.service.CleanRhymeService;
import cn.gov.anhai.service.PublicService;
import cn.gov.anhai.utils.ApiResult;
import cn.gov.anhai.utils.LoginUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 动态
 */
@Slf4j
@RestController
@Api(tags = {"廉韵安海"})
public class CleanRhymeController {
    @Resource
    PublicService publicService;
    @Resource
    CleanRhymeService cleanRhymeService;

    /**
     * 开屏封面
     */
    @GetMapping(value = "/clean-rhyme/back")
    @ApiOperation(value = "开屏封面")
    public ApiResult<Object> back(HttpServletRequest request) throws Exception {
        return ApiResult.ok(cleanRhymeService.back());
    }

    /**
     * 默认路线信息
     */
    @GetMapping(value = "/clean-rhyme/default-way")
    @ApiOperation(value = "默认路线信息")
    public ApiResult<Object> defaultInfo(HttpServletRequest request) throws Exception {
        Map<String, Object> info = cleanRhymeService.defaultInfo();
        if (info == null) ApiResult.fail("查无默认路线");
        return ApiResult.ok(info);
    }

    /**
     * 所有路线信息
     */
    @GetMapping(value = "/clean-rhyme/ways")
    @ApiOperation(value = "所有路线信息")
    public ApiResult<Object> list(HttpServletRequest request) throws Exception {
        List<Map<String, Object>> list = cleanRhymeService.list();
        return ApiResult.ok(list);
    }

    /**
     * 名人列表
     */
    @GetMapping(value = "/famousPerson/list")
    @ApiOperation(value = "名人列表")
    public ApiResult<Object> famousPersonList(Integer current, Integer size, Long wayId, HttpServletRequest request) throws Exception {
        Map<String, Object> result = new HashMap<>();
        List<Map<String, Object>> records = cleanRhymeService.famousPersonList(current, size, wayId);
        Integer total = cleanRhymeService.famousPersonListCount(wayId);
        result.put("records", records);
        result.put("total", total);
        return ApiResult.ok(result);
    }

    /**
     * 名人详情
     */
    @GetMapping(value = "/famousPerson/{id}")
    @ApiOperation(value = "名人详情")
    public ApiResult<Object> famousPersonInfo(@PathVariable("id") Long id, HttpServletRequest request) throws Exception {
        Map<String, Object> info = cleanRhymeService.famousPersonInfo(id);
        if (info == null) return ApiResult.fail("查无名人信息");
        return ApiResult.ok(info);
    }

}
